package com.yunhai.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.model.entity.tms.TmsStoreEntity;
import com.yunhai.model.vo.tms.TmsStoreQuery;
import com.yunhai.model.vo.tms.TmsStoreVo;
import com.yunhai.store.service.TmsStoreService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/store")
public class TmsStoreController {

    @Resource
    private TmsStoreService tmsStoreService;


    /**
     * 获取 TmsStore 分页列表
     */
    @GetMapping("/pagination")
    public Ret getTmsStorePagination(PaginationVo paginationVo, TmsStoreQuery tmsStoreQuery ) throws Exception {
        IPage page = tmsStoreService.getTmsStorePagination(paginationVo, tmsStoreQuery );
        return Ret.toPage(page);
    }


    /**
     * 获取 TmsStore 所有数据
     */
    @GetMapping("/allList")
    public Ret getTmsStoreAllList( TmsStoreQuery tmsStoreQuery ) throws Exception {
        List<TmsStoreEntity> list = tmsStoreService.getTmsStoreAllList( tmsStoreQuery );
        return Ret.ok(list);
    }

    @GetMapping("/condition")
    public List<TmsStoreVo> getTmsStoreByIds(
            @RequestParam("ids") List<Long> ids ) throws Exception {
        List<TmsStoreVo> list = tmsStoreService.getTmsStoreByIds( ids );
        return list;
    }


    /**
     * 获取 TmsStore 详情
    */
   @GetMapping("/{id}")
   public Ret getTmsStoreDetail(@PathVariable Long id) throws Exception {

       TmsStoreEntity tmsStore = tmsStoreService.getTmsStoreDetail(id);
       return Ret.ok(tmsStore);
   }


    /**
     * 新增 TmsStore
     * */
    @PostMapping("")
    public Ret addTmsStore(@RequestBody TmsStoreVo tmsStoreVo) throws Exception {

        tmsStoreService.addTmsStore(tmsStoreVo);
        return Ret.ok();
    }


    @PostMapping("/batchLoad")
    public Ret batchAddTmsStoreByExcelFile(@RequestParam("file") MultipartFile file ) throws Exception {

        tmsStoreService.batchAddTmsStoreByExcelFile( file );
        return Ret.ok();
    }


    /**
     * 更新 TmsStore
     * */
    @PutMapping("")
    public Ret updateTmsStore(@RequestBody TmsStoreVo tmsStoreVo) throws Exception {

        tmsStoreService.updateTmsStore(tmsStoreVo);
        return Ret.ok();
    }


    /**
     * 删除 TmsStore
     * */
    @PostMapping("/batchRemove")
    public Ret batchRemoveTmsStore( @RequestBody List<Long> ids ) throws Exception {

        tmsStoreService.batchRemoveTmsStore(ids);
        return Ret.ok();
    }
}

  